package com.yan.demo.demo6;

import java.util.ArrayList;
import java.util.Iterator;

public class StudentTool {
    public void lisStudents(ArrayList<Student>list){
       list.forEach(item -> System.out.println(item));
    }

    public int getMaxScore(ArrayList<Student>list){
        Integer Max = list.get(0).getScore();
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getScore() > Max){
                Max = list.get(i).getScore();
            }
        }
        return Max;
    }

    public Student getMaxStudent(ArrayList<Student>list){
        Integer Max = list.get(0).getScore();
        Integer index = 0;
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getScore() > Max){
                Max = list.get(i).getScore();
                index = i;
            }
        }
        return list.get(index);
    }

    public int getAverageScore(ArrayList<Student>list){
        Integer avg = 0;
        Integer totle = 0;
        for (int i = 0; i < list.size(); i++) {
            totle += list.get(i).getScore();
        }
        avg = totle / list.size();
        return avg;
    }

    public int getCount(ArrayList<Student>list){
        Integer num = 0;
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getScore() < 60){
                num++;
            }
        }
        return num;
    }
}
